package controller;

import dao.UserDAO;
import entities.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping(value = "/registration")
public class RegistrationController {
    @Autowired
    private UserDAO userDao;

    @RequestMapping(method = RequestMethod.GET)
    public String registration() {
        return "registration";
    }

    @RequestMapping(method = RequestMethod.POST)
    public String register(ModelMap model, @RequestParam("j_username") String email, @RequestParam("j_password") String pass) {
        User user = new User(email, pass, "ROLE_USER");
        userDao.create(user);
        return "/signin";
    }

}
